package com.hq.controller;

import com.hq.bean.User;
import com.hq.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
public class UserController {
    @Resource
    UserService userService;

    @RequestMapping("/login")
    public String login(User user){
        User u=userService.login(user);
        if(u!=null){
            return "success";
        }else{
            return "error";
        }
    }

    @RequestMapping("/register")
    public String register(User user){
        int i=userService.register(user);
        if(i>0){
            return "redirect:tologin";
        }else{
            return "forward:register.jsp";
        }
    }

    @RequestMapping("/tologin")
    public String tologin(){
        return "login";
    }


}
